package com.ruoyi.sjl.config;

import com.ruoyi.sjl.handler.RescueWebSocketHandler;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {
    private final RescueWebSocketHandler rescueWebSocketHandler;

    public WebSocketConfig(RescueWebSocketHandler rescueWebSocketHandler) {
        this.rescueWebSocketHandler = rescueWebSocketHandler;
    }

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(rescueWebSocketHandler, "/ws/{type}/{id}")
                .setAllowedOriginPatterns("*");
    }

}
